/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * STAFF_RECORD.java
 *
 * Created on Sep 29, 2010, 1:17:18 PM
 */

package COMIC_BOOK_STORE;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;

/**
 *
 * @author Alexander
 */
public class STAFF_RECORD extends javax.swing.JFrame {

    Statement stat;
    Connection con;
    ResultSet rset;
    private String url = "jdbc:oracle:thin:@localhost:1521:XE";
   // private String pass_id = "project";
   // private String pass_pw = "1234";
    private DefaultListModel List;
    String tab = "\t";

    /** Creates new form STAFF_RECORD */
    public STAFF_RECORD() throws SQLException {
        super("STAFF RECORD");
        initComponents();
        this.setLocationRelativeTo(null);
        connect();
        populateData();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel1 = new javax.swing.JLabel();
        mainMenuButton = new javax.swing.JButton();
        addButton = new javax.swing.JButton();
        backButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        editButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        staffList = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jLayeredPane1.setFocusable(false);

        jLabel1.setText("STAFF RECORD");
        jLabel1.setBounds(30, 20, 120, 30);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        mainMenuButton.setText("MAIN MENU");
        mainMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainMenuButtonActionPerformed(evt);
            }
        });
        mainMenuButton.setBounds(660, 340, 140, 40);
        jLayeredPane1.add(mainMenuButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        addButton.setText("ADD");
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });
        addButton.setBounds(660, 140, 140, 40);
        jLayeredPane1.add(addButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        backButton.setText("BACK");
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });
        backButton.setBounds(660, 290, 140, 40);
        jLayeredPane1.add(backButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        deleteButton.setText("DELETE");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });
        deleteButton.setBounds(660, 240, 140, 40);
        jLayeredPane1.add(deleteButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        editButton.setText("EDIT");
        editButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editButtonActionPerformed(evt);
            }
        });
        editButton.setBounds(660, 190, 140, 40);
        jLayeredPane1.add(editButton, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator1.setBounds(20, 52, 460, 10);
        jLayeredPane1.add(jSeparator1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jScrollPane1.setViewportView(staffList);

        jScrollPane1.setBounds(30, 90, 470, 320);
        jLayeredPane1.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setText("Staff Code");
        jLabel2.setBounds(30, 70, 80, -1);
        jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setText("Staff IC");
        jLabel3.setBounds(150, 70, 60, -1);
        jLayeredPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setText("Staff Name");
        jLabel4.setBounds(300, 70, 70, -1);
        jLayeredPane1.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGE_REPOSITORY/Background3 copy.jpg"))); // NOI18N
        jLabel5.setText("jLabel5");
        jLabel5.setBounds(0, 0, 900, 500);
        jLayeredPane1.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 900, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        try {
            new STAFF_DELETE().setVisible(true);
        } catch (SQLException ex) {
            Logger.getLogger(STAFF_RECORD.class.getName()).log(Level.SEVERE, null, ex);
        }
    this.setVisible(false);// TODO add your handling code here:
    }                                            

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
        new ADMIN_CONSOLE().setVisible(true);
        this.setVisible(false);        // TODO add your handling code here:
    }                                          

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
        try {
            new STAFF_ADD().setVisible(true);
        } catch (SQLException ex) {
            Logger.getLogger(STAFF_RECORD.class.getName()).log(Level.SEVERE, null, ex);
        }
    this.setVisible(false);
    }                                         

    private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
        try {
            new STAFF_EDIT().setVisible(true);
        } catch (SQLException ex) {
            Logger.getLogger(STAFF_RECORD.class.getName()).log(Level.SEVERE, null, ex);
        }
       this.setVisible(false);// TODO add your handling code here:
    }                                          

    private void mainMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               

        new MAIN_MENU().setVisible(true);
        this.setVisible(false);// TODO add your handling code here:
    }                                              

      private void connect() throws SQLException
    {
        DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
        System.out.println("Driver Loaded");
        con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","javaproject","javaproject");
        System.out.println("Database Connected");

    }
      private void populateData() throws SQLException
    {
        String query = "SELECT * FROM STAFF ORDER BY STAFF_CODE ASC";
        List = new DefaultListModel();
        stat = con.createStatement();
        rset = stat.executeQuery(query);
        while(rset.next())
        {
            List.addElement(rset.getString("STAFF_CODE")+"                         "+tab+ rset.getString("STAFF_ICNO") +"                        "+tab+ rset.getString("STAFF_FNAME"));
        } 
        staffList.setModel(List);
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new STAFF_RECORD().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(STAFF_RECORD.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton addButton;
    private javax.swing.JButton backButton;
    private javax.swing.JButton deleteButton;
    private javax.swing.JButton editButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton mainMenuButton;
    private javax.swing.JList staffList;
    // End of variables declaration                   

}
